<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

    <!-- <script>
        function delay(ms) {
            return new Promise((resolve, reject) => {
                setTimeout(resolve, ms)
            })
        }

        const p1 = delay(1000)
        const p2 = delay(2000)
        const p3 = delay(500).then(() => Promise.reject())
        const begin = Date.now()
        Promise.race([p1, p2, p3, 1]).then(
            v => {
                console.log('成功', v, Date.now() - begin);
            },
            v => {
                console.log('失败', v, Date.now() - begin);
            },
        )

    </script> -->

    <script>
        function delay(ms) {
            return new Promise((resolve, reject) => {
                setTimeout(resolve, ms)
            })
        }
        const p1 = delay(1000).then(() => { throw 1 })
        const p2 = delay(2000).then(() => { throw 2 })
        const p3 = delay(1500).then(() => { throw 3 })
        const p4 = delay(500).then(() => { throw 4 })
        const p = Promise.any([p1, p2, p3, p4])
        const begin = Date.now()
        p.then((v) => console.log(v, Date.now() - begin),
            (e) => console.log(e.errors, Date.now() - begin)
        )


    </script>

    <!-- <script>
        function delay(ms) {
            return new Promise((resolve, reject) => {
                setTimeout(resolve, ms)
            })
        }

        const p1 = delay(1000).then(() => { throw 1 })
        const p2 = delay(2000).then(() => { return 2 })
        const p3 = delay(1500).then(() => { throw 3 })
        const p4 = delay(500).then(() => { throw 4 })
        const p = Promise.allSettled([p1, p2, p3, p4])
        const begin = Date.now()
        p.then((v) => console.log(v, Date.now() - begin),
            (e) => console.log(e.errors, Date.now() - begin)
        )
    </script> -->
</body>

</html>